<?php

function data_harian_karyawan($karyawan_id ){
	$date_start = isset($_GET['date_start']) ? $_GET['date_start'] : date('d-m-Y'); 
	$date_end = isset($_GET['date_end']) ? $_GET['date_end'] :  date('d-m-Y');
	
my_set_file_js(
	array(
		'components/system/jquery/combomulti/jquery.chainedSelects.js',
		'components/system/js/calendar/calendarDateInput.js' 
	)
);
	list( $dds,$mms, $yyyys) = explode('-', $date_start);
	list( $dde,$mme, $yyyye) = explode('-', $date_end);
	$date_startx = $yyyys.'-'.$mms.'-'.$dds;
	$date_endx = $yyyye.'-'.$mme.'-'.$dde;
	
	$header = array(
		'Tanggal'=>array('style'=>'text-align:center;border-bottom:2px solid;width:20%'),   
		'Waktu Finger'=>array('style'=>'text-align:center;border-bottom:2px solid;width:20%'), 
		'Terminal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:60%'), 
	);
	$query = "SELECT * FROM a_mesin_capture a
		INNER JOIN a_mesin_lokasi b ON b.id = a.mesin_lokasi_id 
		WHERE a.karyawan_mesin_id = {$karyawan_id} 
		AND ( DATE(a.datetime_mesin_log) BETWEEN '{$date_startx}' AND '{$date_endx}' )
		ORDER BY a.datetime_mesin_log ASC"; 
	 
	$result = my_query($query );
 
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =15;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&karyawan_id={$karyawan_id}&date_start={$date_start}&date_end={$date_end}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while( $ey = my_fetch_array($result) ){
		$row[] = array(
			'tgl'=>position_text_align(date('d-m-Y' , strtotime($ey['datetime_mesin_log'])) ,'center'),
			'time'=>position_text_align(date('H:i' , strtotime($ey['datetime_mesin_log'])) ,'center'),
			'lokasi'=>position_text_align($ey['lokasi']  , 'left')
		);
	}
	
	$datas = table_rows($row); 
	$date_start_form = array(
			'name'=>'date_start',
			'id'=>'date_start',
			'value'=>$date_start,
		);
	
	$date_end_form = array(
			'name'=>'date_end',
			'id'=>'date_end',
			'value'=>$date_end,
		);
	
		$src ="<form method=\"GET\">

	<input type=\"hidden\" name=\"com\" value=\"{$_GET['com']}\" />
	<input type=\"hidden\" name=\"task\" value=\"{$_GET['task']}\" />
	<input type=\"hidden\" name=\"karyawan_id\" value=\"{$_GET['karyawan_id']}\" />
	<table border=\"0\" width=\"100%\"> <tr><td width='20%'>
	Tanggal&nbsp;:</td><td width='20%'>".form_calendar($date_start_form)." </td>
	<td width='5%'>s/d</td><td width='20%'> ".form_calendar($date_end_form)."</td><td width=\"10%\"> 
	<input type=\"submit\" value=\"GO\" class=\"simple_search\"/></td> </tr></table></form>";
	
	$printmenu = additional_menu_on_list( array() , $src); 
	
	$paging = $kgPagerOBJ ->showPaging();
	return  $printmenu .   table_builder($header , $datas , 3 , false ,$paging );	
}



function get_terminal_by_ip($ip){
	$query = "SELECT lokasi FROM a_mesin_lokasi WHERE ip_lokasi ='{$ip}' ";
	$res = my_query($query);
	$row = my_fetch_array($res);
	return $row['lokasi'];
}